<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品下单支付页</title>
</head>
<body>
<div class="container">
    <div class="product-info">
        <h2>支付测试</h2>
        <p>价格：0.01</p>
    </div>
    <button id="orderButton" class="order-button">立即下单「支付宝沙箱支付」mrt</button>
    <span class="account-info">测试账号：ornqju3629@sandbox.com 密码：111111 支付：111111</span>
</div>

<script>
document.getElementById('orderButton').addEventListener('click', function() {
    var userId = "xfg";
    var productId = "1001";
    var url = 'http://localhost:80/api/v1/sale/create_pay_order?userId=' + userId + '&productId=' + productId;

    fetch(url, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        }
    })
    .then(response => response.json()) // 解析JSON格式的响应
    .then(json => {
        if (json.code === "0000") { // 假设成功的code是"success"
            var formHtml = json.data; // 获取data字段中的HTML表单字符串
            document.body.innerHTML += formHtml; // 将表单添加到页面上
            document.forms[0].submit(); // 自动提交表单
        } else {
            console.error('Error:', json.info); // 输出错误信息
        }
    })
    .catch(error => console.error('Error:', error));
});
</script>
</body>
</html>

